package com.nuedu.corejava.ch10;

import java.util.TreeSet;

public class TreeSetClass {

	public static void main(String[] args) {
		
		//TreeSet保存的数据类型需要实现java.lang.Compareable接口
		//在保存数据时会进行类型检查，如果没有实现java.lang.Compareable接口会报类型转换异常
		TreeSet<Computer> treeSet = new TreeSet<Computer>();
		treeSet.add(new Computer("HP1",50000));
		treeSet.add(new Computer("HP2",50000));
		treeSet.add(new Computer("HP3",50000));
		treeSet.add(new Computer("HW1",50000));
		treeSet.add(new Computer("HP1",50000));
		treeSet.add(new Computer("DELL1",50000));
		treeSet.add(new Computer("DELL2",50000));
		/*
		 * //使用first和remove方法遍历TreeSet Computer computer = treeSet.first(); while
		 * (computer!= null) { System.out.println(computer); treeSet.remove(computer);
		 * 
		 * 
		 * }
		 */
		Computer computer = treeSet.first();
		Computer computer2 = treeSet.last();
		System.out.println(computer);
		System.out.println(computer2);
		
		//以队列形式进行操作
		//computer = treeSet.pollFirst();
		computer = treeSet.pollLast();
		while (computer!=null) {
			System.out.println(computer);
			//computer = treeSet.pollFirst();
			computer = treeSet.pollLast();
			
		}

	}

}
